ALMaSS  1.0
The Animal, Landscape and Man Simulation System
Partridge_Communication Class Reference

Used for messaging. More...

#include <Partridge_Communication.h>

Public Member Functions

void ClearData (PartridgeCommunicationData *pc_data)
 Void data. More...
 
bool PassMessage (PartridgeCommunicationData *pc_data, TypeOfPartridge_Communication pc)
 Pass a message. More...
 

Detailed Description

Used for messaging.

Messages are passed between birds, and this a common cause of bugs if the information passed in inconsistent. This class therefore has two purposes - collecting messaging code together for ease of overview, and as a debug function.

Member Function Documentation

◆ ClearData()

void Partridge_Communication::ClearData ( PartridgeCommunicationData pc_data)

Void data.

Just makes sure that all message fields are empty. Used before putting new data in.

66  {
67  pc_data->m_clutch=NULL;
68  pc_data->m_chick=NULL;
69  pc_data->m_chick2=NULL;
70  pc_data->m_male=NULL;
71  pc_data->m_female=NULL;
72  pc_data->m_covey=NULL;
73  pc_data->m_HaveTerritory=false;
74  pc_data->m_boolean=false;
75  pc_data->m_int=0;
76  pc_data->m_float=0;
77 }
Partridge_Covey * m_covey
Definition: Partridge_Communication.h:85
Partridge_Female * m_female
Definition: Partridge_Communication.h:84
Partridge_Chick * m_chick
Definition: Partridge_Communication.h:81
Partridge_Male * m_male
Definition: Partridge_Communication.h:83
bool m_HaveTerritory
Definition: Partridge_Communication.h:86
Partridge_Clutch * m_clutch
Definition: Partridge_Communication.h:80
bool m_boolean
Definition: Partridge_Communication.h:87
Partridge_Chick2 * m_chick2
Definition: Partridge_Communication.h:82
int m_int
Definition: Partridge_Communication.h:88
double m_float
Definition: Partridge_Communication.h:89

References PartridgeCommunicationData::m_boolean, PartridgeCommunicationData::m_chick, PartridgeCommunicationData::m_chick2, PartridgeCommunicationData::m_clutch, PartridgeCommunicationData::m_covey, PartridgeCommunicationData::m_female, PartridgeCommunicationData::m_float, PartridgeCommunicationData::m_HaveTerritory, PartridgeCommunicationData::m_int, and PartridgeCommunicationData::m_male.

◆ PassMessage()

bool Partridge_Communication::PassMessage ( PartridgeCommunicationData pc_data,
TypeOfPartridge_Communication  pc 
)

Pass a message.

This passes messages listed in the TypeOfPartridge_Communication enum. It is a place that errors can be trapped but is not strictly necessary. Data is passed in PartridgeCommunicationData which can be checked agains the sender and the receiver information if __PAR_PCDEBUG is enabled.
This complex method is not really necessary, but it is a wonderful place to trap communication errors. If run-times really get to be a problem, then it might be worth dispensing with this nicety.

86  {
87  switch (pc) {
88  case pcomm_KillChick:
89  #ifdef __PAR_PCDEBUG
90  if (pc_data->m_chick->GetObjectType() != pob_Chick) {
91  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_KillChick" );
92  exit(101);
93  }
94  #endif
95  pc_data->m_chick->OnYouAreDead(); // No data to pass
96  break;
97  case pcomm_Mating:
98  #ifdef __PAR_PCDEBUG
99  if (pc_data->m_female->GetMate() != NULL) {
100  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_Mating" );
101  exit(102);
102  }
103  #endif
104  pc_data->m_female->OnMating(pc_data);
105  break;
106  case pcomm_MatingM:
107  #ifdef __PAR_PCDEBUG
108  if (pc_data->m_male->GetMate() != NULL) {
109  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MatingM" );
110  exit(102);
111  }
112  #endif
113  pc_data->m_male->OnMating(pc_data->m_female);
114  break;
115  case pcomm_MaleDying:
116  #ifdef __PAR_PCDEBUG
117  if (pc_data->m_female->GetMate() != pc_data->m_male) {
118  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MaleDying" );
119  exit(103);
120  }
121  #endif
122  pc_data->m_female->OnMateDying(pc_data);
123  break;
124  case pcomm_EggsHatch:
125  #ifdef __PAR_PCDEBUG
126  if (pc_data->m_female->GetClutch() != pc_data->m_clutch) {
127  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_EggsHatch1" );
128  exit(104);
129  }
130  if ( pc_data->m_male ) if (pc_data->m_male->GetMate() != pc_data->m_female) {
131  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_EggsHatch2" );
132  exit (113);
133  }
134  if ((pc_data->m_female->GetMate() == NULL)&& ( pc_data->m_male != NULL)) {
135  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_EggsHatch3" );
136  exit (113);
137  }
138  #endif
139  // It is possible that there is no male if he was killed under incubation
140  if ( pc_data->m_male ) pc_data->m_male->OnLookAfterKids( );
141  pc_data->m_female->OnEggsHatch();
142  break;
143  case pcomm_SetClutch:
144  #ifdef __PAR_PCDEBUG
145  if (pc_data->m_female->WhatState() != pars_FMakingNest) {
146  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_SetClutch" );
147  exit(111);
148  }
149  #endif
150  pc_data->m_female->OnSetMyClutch(pc_data);
151  break;
152  case pcomm_WaitForMale:
153  #ifdef __PAR_PCDEBUG
154  if (pc_data->m_female->GetMate() != NULL) {
155  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_WaitForMale" );
156  exit(106);
157  }
158  #endif
159  pc_data->m_female->OnWaitForMale();
160  break;
161  case pcomm_ClutchDead:
162  #ifdef __PAR_PCDEBUG
163  if (pc_data->m_female->GetClutch() != pc_data->m_clutch) {
164  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_ClutchDead" );
165  exit(107);
166  }
167  #endif
168  pc_data->m_female->OnClutchDeath();
169  break;
170  case pcomm_AllInfertile:
171  #ifdef __PAR_PCDEBUG
172  if (pc_data->m_female->GetClutch() != pc_data->m_clutch) {
173  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_ClutchDead" );
174  exit(107);
175  }
176  #endif
177  pc_data->m_female->OnClutchDeath();
178  break;
179  case pcomm_ClutchMown:
180  #ifdef __PAR_PCDEBUG
181  if (pc_data->m_female->GetClutch() != pc_data->m_clutch) {
182  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_ClutchMown" );
183  exit(107);
184  }
185  #endif
186  pc_data->m_female->OnClutchMown();
187  break;
188  case pcomm_MumDeadC:
189  // Possible to get here and have an old mate but no mate
190  if (pc_data->m_female->GetOldMate() != NULL) {
191  #ifdef __PAR_PCDEBUG
192  if (pc_data->m_female != pc_data->m_female->GetOldMate()->GetOldMate()) {
193  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MumDeadC3 - old mate mismatch" );
194  exit(117);
195  }
196  #endif
197  pc_data->m_female->GetOldMate()->RemoveOldMate(false);
198  }
199  // Possible that this is called with no male
200  if (pc_data->m_male != NULL) {
201  #ifdef __PAR_PCDEBUG
202  if (pc_data->m_female->GetMate() != pc_data->m_male) {
203  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MumDeadC1" );
204  exit(108);
205  }
206  #endif
207  pc_data->m_male->OnMateDying();
208  }
209  // Quite possible this is called with no clutch
210  if (pc_data->m_clutch != NULL) {
211  #ifdef __PAR_PCDEBUG
212  if ((pc_data->m_female->WhatState() != pars_FIncubating) && (pc_data->m_female->WhatState() != pars_FLaying)) {
213  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MumDeadC2" );
214  exit(112);
215  }
216  #endif
217  pc_data->m_clutch->OnMumDead();
218  }
219  break;
221  #ifdef __PAR_PCDEBUG
222  if (pc_data->m_female->GetMate() != pc_data->m_male) {
223  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_FemaleGivingUp" );
224  exit(109);
225  }
226  #endif
227  pc_data->m_male->OnFemaleGivingUp();
228  break;
229  case pcomm_ClutchEaten:
230  #ifdef __PAR_PCDEBUG
231  if (pc_data->m_female->GetClutch() == NULL) {
232  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_ClutchEaten" );
233  exit(110);
234  }
235  #endif
236  pc_data->m_clutch->OnEaten();
237  break;
238  case pcomm_AllChicksDead:
239  #ifdef __PAR_PCDEBUG
240  if (pc_data->m_female) if (pc_data->m_female->GetMate() != pc_data->m_male) {
241  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_AllChicksDead" );
242  exit(111);
243  }
244  #endif
245  // All chicks are dead so tell the sad news to the parents, if they live
246  if (pc_data->m_male) pc_data->m_male->OnChicksDead();
247  if (pc_data->m_female) {
248  pc_data->m_female->OnChicksDead();
249  }
250  break;
251  case pcomm_ChicksMature:
252  #ifdef __PAR_PCDEBUG
253  if (pc_data->m_female) if (pc_data->m_female->GetMate() != pc_data->m_male) {
254  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_ChickMature" );
255  exit(114);
256  }
257  #endif
258  // All chicks are dead so tell the sad news to the parents, if they live
259  if (pc_data->m_male) pc_data->m_male->OnChicksMatured();
260  if (pc_data->m_female) pc_data->m_female->OnChicksMatured();
261  break;
263  #ifdef __PAR_PCDEBUG
264  if (pc_data->m_female->GetMate() != pc_data->m_male) {
265  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_StoppingBreeding" );
266  exit(115);
267  }
268  #endif
269  pc_data->m_male->OnStoppingBreeding();
270  break;
271  case pcomm_MovingHome:
272  #ifdef __PAR_PCDEBUG
273  if (pc_data->m_female->GetMate() != pc_data->m_male) {
274  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "pcomm_MovingHome" );
275  exit(116);
276  }
277  #endif
278  pc_data->m_male->OnMovingHome();
279  break;
280  default:
281  g_msg->Warn( WARN_BUG, "Partridge_Communication::PassMessage():", "No matching message" );
282  exit(199);
283  }
284  #ifdef __PARPCDEBUG
285  ClearData(pc_data);
286  #endif
287  return true;
288 }
@ pars_FLaying
Definition: Partridge_All.h:282
@ pars_FIncubating
Definition: Partridge_All.h:283
@ pars_FMakingNest
Definition: Partridge_All.h:282
@ pob_Chick
Definition: Partridge_All.h:297
@ pcomm_MatingM
Definition: Partridge_Communication.h:58
@ pcomm_MumDeadC
Definition: Partridge_Communication.h:66
@ pcomm_EggsHatch
Definition: Partridge_Communication.h:61
@ pcomm_SetClutch
Definition: Partridge_Communication.h:62
@ pcomm_StoppingBreeding
Definition: Partridge_Communication.h:69
@ pcomm_WaitForMale
Definition: Partridge_Communication.h:64
@ pcomm_ClutchMown
Definition: Partridge_Communication.h:65
@ pcomm_FemaleGivingUp
Definition: Partridge_Communication.h:67
@ pcomm_AllChicksDead
Definition: Partridge_Communication.h:63
@ pcomm_ClutchDead
Definition: Partridge_Communication.h:59
@ pcomm_ChicksMature
Definition: Partridge_Communication.h:56
@ pcomm_KillChick
Definition: Partridge_Communication.h:54
@ pcomm_ClutchEaten
Definition: Partridge_Communication.h:68
@ pcomm_MovingHome
Definition: Partridge_Communication.h:70
@ pcomm_AllInfertile
Definition: Partridge_Communication.h:60
@ pcomm_MaleDying
Definition: Partridge_Communication.h:55
@ pcomm_Mating
Definition: Partridge_Communication.h:57
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
Partridge_Object GetObjectType()
Supply object type.
Definition: Partridge_All.h:432
void OnYouAreDead()
Message handler.
Definition: Partridge_All.cpp:1016
void OnMumDead()
Message handler.
Definition: Partridge_All.cpp:617
void OnEaten()
Message handler.
Definition: Partridge_All.cpp:645
void ClearData(PartridgeCommunicationData *pc_data)
Void data.
Definition: Partridge_Communication.cpp:66
Partridge_Clutch * GetClutch(void)
Supply clutch pointer.
Definition: Partridge_All.h:867
void OnClutchDeath()
Message handler.
Definition: Partridge_All.cpp:2056
void OnMating(PartridgeCommunicationData *pc_datae)
Message handler.
Definition: Partridge_All.cpp:2031
void OnWaitForMale()
Message handler.
Definition: Partridge_All.cpp:2015
void OnClutchMown()
Message handler.
Definition: Partridge_All.cpp:2069
void OnMateDying(PartridgeCommunicationData *pc_data)
Message handler.
Definition: Partridge_All.cpp:2129
Partridge_Male * GetMate(void)
Supply mate pointer.
Definition: Partridge_All.h:872
Partridge_Male * GetOldMate(void)
Supply old mate pointer.
Definition: Partridge_All.h:893
void OnEggsHatch()
Message handler.
Definition: Partridge_All.cpp:2096
void OnChicksMatured()
Message handler.
Definition: Partridge_All.cpp:2107
void OnSetMyClutch(PartridgeCommunicationData *pc_data)
Message handler.
Definition: Partridge_All.cpp:2086
void OnChicksDead()
Message handler.
Definition: Partridge_All.cpp:2118
void OnMateDying()
Message handler.
Definition: Partridge_All.cpp:2761
void OnChicksMatured()
Message handler.
Definition: Partridge_All.cpp:2699
void OnLookAfterKids(void)
Message handler.
Definition: Partridge_All.cpp:2675
void OnMating(Partridge_Female *a_mate)
Message handler.
Definition: Partridge_All.cpp:2738
void RemoveOldMate(bool a_knockon)
Forget any old mate.
Definition: Partridge_All.cpp:2661
Partridge_Female * GetMate(void)
Are we paired?
Definition: Partridge_All.h:719
void OnStoppingBreeding()
Message handler.
Definition: Partridge_All.cpp:2709
void OnMovingHome()
Message handler.
Definition: Partridge_All.cpp:2729
void OnFemaleGivingUp()
Message handler.
Definition: Partridge_All.cpp:2783
void OnChicksDead()
Message handler.
Definition: Partridge_All.cpp:2689
Partridge_Female * GetOldMate(void)
Supply old mate pointer.
Definition: Partridge_All.h:757
virtual int WhatState()
Definition: PopulationManager.h:263
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_BUG
Definition: maperrormsg.h:34

References g_msg, Partridge_Female::GetClutch(), Partridge_Male::GetMate(), Partridge_Female::GetMate(), Partridge_Base::GetObjectType(), Partridge_Male::GetOldMate(), Partridge_Female::GetOldMate(), PartridgeCommunicationData::m_chick, PartridgeCommunicationData::m_clutch, PartridgeCommunicationData::m_female, PartridgeCommunicationData::m_male, Partridge_Male::OnChicksDead(), Partridge_Female::OnChicksDead(), Partridge_Male::OnChicksMatured(), Partridge_Female::OnChicksMatured(), Partridge_Female::OnClutchDeath(), Partridge_Female::OnClutchMown(), Partridge_Clutch::OnEaten(), Partridge_Female::OnEggsHatch(), Partridge_Male::OnFemaleGivingUp(), Partridge_Male::OnLookAfterKids(), Partridge_Male::OnMateDying(), Partridge_Female::OnMateDying(), Partridge_Male::OnMating(), Partridge_Female::OnMating(), Partridge_Male::OnMovingHome(), Partridge_Clutch::OnMumDead(), Partridge_Female::OnSetMyClutch(), Partridge_Male::OnStoppingBreeding(), Partridge_Female::OnWaitForMale(), Partridge_Chick::OnYouAreDead(), pars_FIncubating, pars_FLaying, pars_FMakingNest, pcomm_AllChicksDead, pcomm_AllInfertile, pcomm_ChicksMature, pcomm_ClutchDead, pcomm_ClutchEaten, pcomm_ClutchMown, pcomm_EggsHatch, pcomm_FemaleGivingUp, pcomm_KillChick, pcomm_MaleDying, pcomm_Mating, pcomm_MatingM, pcomm_MovingHome, pcomm_MumDeadC, pcomm_SetClutch, pcomm_StoppingBreeding, pcomm_WaitForMale, pob_Chick, Partridge_Male::RemoveOldMate(), MapErrorMsg::Warn(), WARN_BUG, and TAnimal::WhatState().

Referenced by Partridge_Clutch::AgDying(), Partridge_Clutch::ClDeveloping(), Partridge_Population_Manager::CreateObjects(), Partridge_Population_Manager::DissolveCovey(), Partridge_Female::FDying(), Partridge_Female::FFindingTerritory(), Partridge_Female::FIncubating(), Partridge_Female::FLaying(), Partridge_Female::FMakingNest(), Partridge_Female::FStartingNewBrood(), Partridge_Male::MDying(), Partridge_Male::MFindingMate(), Partridge_Covey::OnChickDeath(), and Partridge_Covey::OnChickMature().


The documentation for this class was generated from the following files: